#!/usr/bin/env python
# -*- coding: utf-8 -*-


def select_sort(items, comp=lambda x, y: x < y):
    """简单选择排序"""
    items = items[:]
    for i in range(len(items) - 1):
        min_index = i
        for j in range(i + 1, len(items)):
            if comp(items[j], items[min_index]):
                min_index = j
        items[i], items[min_index] = items[min_index], items[i]
    return items


# print(select_sort(items=[1, 4, 6, 2, 9]))


def bubble_sort(items, comp=lambda x, y: x > y):
    new_list = items[:]
    for i in range(len(new_list) - 1):
        for j in range(len(new_list) - 1 - i):
            if comp(new_list[j], new_list[j + 1]):
                new_list[j], new_list[j + 1] = new_list[j + 1], new_list[j]
    return new_list


testlist = [27, 33, 28, 4, 2, 26, 13, 35, 8, 14]
print('bubble_sort:', bubble_sort(testlist))


def seq_search(items, key):
    for index, item in enumerate(items):
        if item == key:
            return index
    return -1


print('seq_search:', seq_search(testlist, 35))

# 百钱百鸡问题，求最优解:
# 公鸡5元一只，母鸡3元一只，小鸡1元一只；
# 用100元买一百只鸡，请问公鸡/母鸡/小鸡各多少只？
for x in range(20):
    for y in range(33):
        z = 100 - x - y
        if 5 * x + 3 * y + z // 3 == 100 and z % 3 == 0:
            print(x, y, z)
